home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include "filefunc.h"
- #include "graph.h"
- #include "drvrfuncs.h"
- #include "sbsimdmo.h"
-
- WINDOW sbwin[2] = {{VIEWABLE | SELECTABLE, " Digital Voice Files ", {5, 7},
- {33, 15}, 0, 0, {NULL, NULL, NULL, NULL}},
- {VIEWABLE | SELECTABLE, " Music Files ", {43, 7},
- {33, 15}, 0, 0, {NULL, NULL, NULL, NULL}}};
-
- void main(void)
- {
- DVRINFO ctvoice;
- DVRINFO ctvdsk;
- DVRINFO auxdrv;
- DVRINFO sbfmdrv;
- DVRINFO sbmidi;
-
- int current;
- int stat;
- int error;
- int i;
- unsigned newLvl;
- char choice = 0;
-
- InitScreen();
-
- // locate SBSIM driver
- if((SIMint = FindDvr("SBSIM", 0x103)) == 0)
- {
- DrawError("SBSIM driver not loaded");
- DemoExit(EXIT_FAILURE);
- }
-
- // Get driver information
- GetDvrInfo(MemVoice, &ctvoice);
- GetDvrInfo(DskVoice, &ctvdsk);
- GetDvrInfo(FM, &sbfmdrv);
- GetDvrInfo(Midi, &sbmidi);
-
- // CTVDSK driver loaded?
- if(ctvdsk.status == MISSING)
- sbwin[0].status &= ~SELECTABLE;
-
- // SBFMDRV and SBMIDI drivers loaded?
- if((sbfmdrv.status == MISSING) && (sbmidi.status == MISSING))
- sbwin[1].status &= ~SELECTABLE;
-
- // AUXDRV driver loaded?
- if(GetDvrInfo(AuxDrv, &auxdrv) == MISSING)
- mixer = OFF;
- else
- {
- mixer = ON;
- // get current volumes
- GetVolume(VOICE, &sbwin[0].mixLvl);
- sbwin[0].mixLvl &= 0xff; // just use the right channel
- GetVolume(SYNTH, &sbwin[1].mixLvl);
- sbwin[1].mixLvl &= 0xff; // just use the right channel
- }
-
- // display driver information window
- if(DrawDrvrInfo(4, 9, Version(), &ctvoice, &ctvdsk, &auxdrv, &sbfmdrv,
- &sbmidi) == ERROR)
- DrawError(memErr);
-
- // Get VOC, MID, and CMF file names
- GetFiles(sbmidi.status, sbfmdrv.status);
-
- current = (sbwin[0].status & SELECTABLE)? 0 : 1;
- // draw digital voice (VOC) window
- DrawWindow(&sbwin[0], (current == 0)? HIGHLIGHT : NORMAL);
- // draw music (MID/CMF) window
- DrawWindow(&sbwin[1], ((current == 1) && (sbwin[1].status & SELECTABLE))?
- HIGHLIGHT : NORMAL);
-
- // error if no files are available
- if(!(sbwin[0].status & SELECTABLE) && !(sbwin[1].status & SELECTABLE))
- {
- DrawError("No VOC, MID, or CMF files available in this directory.");
- DemoExit(EXIT_FAILURE);
- }
-
- do
- {
- while(!kbhit())
- {
- if(sbwin[0].status & SELECTABLE)
- if(sbwin[0].fileList.active != NULL)
- {
- // if VOC file playing, check for status STOPPED
- if((GetSndStat(DskVoice) == STOPPED) &&
- (sbwin[0].fileList.active->status != STOPPED))
- {
- // update display to reflect change
- sbwin[0].fileList.active->status = STOPPED;
- sbwin[0].fileList.active = NULL;
- DrawFileList(&sbwin[0], (current == 0)? HIGHLIGHT : NORMAL);
- }
- }
- if(sbwin[1].status & SELECTABLE)
- if(sbwin[1].fileList.active != NULL)
- // if MID or CMF file is playing, check for status STOPPED
- if((GetSndStat(FindFileType(sbwin[1].fileList.active->filename))
- == STOPPED) && (sbwin[1].fileList.active->status != STOPPED))
- {
- // update display to reflect change
- sbwin[1].fileList.active->status = STOPPED;
- sbwin[1].fileList.active = NULL;
- DrawFileList(&sbwin[1], (current == 1)? HIGHLIGHT : NORMAL);
- }
- }
- // keyboard event processing
- choice = getch();
- switch(choice)
- {
- case TAB:
- // can we switch to other window?
- if(sbwin[current ^ 1].status & SELECTABLE)
- {
- // display windows switched
- DrawWindow(&sbwin[current], NORMAL);
- current ^= 1;
- DrawWindow(&sbwin[current], HIGHLIGHT);
- }
- break;
-
- case LEFT:
- if((mixer == ON) && (sbwin[current].mixLvl >= 8))
- {
- newLvl = sbwin[current].mixLvl - 8;
- SetVolume((current == 0)? VOICE : SYNTH, (newLvl << 8) + newLvl);
- DrawSlider(&sbwin[current], newLvl, HIGHLIGHT);
- }
- break;
-
- case RIGHT:
- if((mixer == ON) && (sbwin[current].mixLvl < 248))
- {
- newLvl = sbwin[current].mixLvl + 8;
- SetVolume((current == 0)? VOICE : SYNTH, (newLvl << 8) + newLvl);
- DrawSlider(&sbwin[current], newLvl, HIGHLIGHT);
- }
- break;
- case UP:
- if(sbwin[current].fileList.current != sbwin[current].fileList.start)
- sbwin[current].fileList.current = sbwin[current].fileList.current->prev;
- else
- if(sbwin[current].fileList.start->prev != NULL)
- {
- sbwin[current].fileList.start = sbwin[current].fileList.start->prev;
- sbwin[current].fileList.stop = sbwin[current].fileList.stop->prev;
- sbwin[current].fileList.current = sbwin[current].fileList.start;
- }
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case DOWN:
- if(sbwin[current].fileList.current != sbwin[current].fileList.stop)
- sbwin[current].fileList.current = sbwin[current].fileList.current->next;
- else
- if(sbwin[current].fileList.stop->next != NULL)
- {
- sbwin[current].fileList.start = sbwin[current].fileList.start->next;
- sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
- sbwin[current].fileList.current = sbwin[current].fileList.stop;
- }
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case PGUP:
- for(i = 0; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1)))
- && (sbwin[current].fileList.start->prev != NULL); i++)
- {
- sbwin[current].fileList.start = sbwin[current].fileList.start->prev;
- sbwin[current].fileList.stop = sbwin[current].fileList.stop->prev;
- sbwin[current].fileList.current = sbwin[current].fileList.current->prev;
- }
- for(; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1))) &&
- (sbwin[current].fileList.current != sbwin[current].fileList.start); i++)
- sbwin[current].fileList.current = sbwin[current].fileList.current->prev;
-
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case PGDOWN:
- for(i = 0; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1)))
- && (sbwin[current].fileList.stop->next != NULL); i++)
- {
- sbwin[current].fileList.start = sbwin[current].fileList.start->next;
- sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
- sbwin[current].fileList.current = sbwin[current].fileList.current->next;
- }
- for(; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1))) &&
- (sbwin[current].fileList.current != sbwin[current].fileList.stop); i++)
- sbwin[current].fileList.current = sbwin[current].fileList.current->next;
-
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case HOME:
- sbwin[current].fileList.start = sbwin[current].fileList.head;
- sbwin[current].fileList.current = sbwin[current].fileList.head;
- sbwin[current].fileList.stop = sbwin[current].fileList.head;
- for(i = 1; (i < (sbwin[current].size.y - ((mixer == ON)? 3 : 1))) &&
- (sbwin[current].fileList.stop->next != NULL) ; i++)
- sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case END:
- while(sbwin[current].fileList.stop->next != NULL)
- {
- sbwin[current].fileList.start = sbwin[current].fileList.start->next;
- sbwin[current].fileList.stop = sbwin[current].fileList.stop->next;
- }
- sbwin[current].fileList.current = sbwin[current].fileList.stop;
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case ENTER:
- switch(sbwin[current].fileList.current->status)
- {
- case STOPPED:
- if(sbwin[current].fileList.active != NULL)
- {
- sbwin[current].fileList.active->status = STOPPED;
- StopSnd(FindFileType(sbwin[current].fileList.active->filename));
- }
- sbwin[current].fileList.current->status = PLAYING;
- sbwin[current].fileList.active = sbwin[current].fileList.current;
- error = StartSnd(FindFileType(sbwin[current].fileList.current->filename),
- sbwin[current].fileList.current->filename, NULL, NULL);
- if(error == SIMerr_NoErr)
- {
- error = PlaySnd(FindFileType(sbwin[current].fileList.current->filename));
- if(error == SIMerr_NoErr)
- {
- sbwin[current].fileList.current->status = PLAYING;
- sbwin[current].fileList.active = sbwin[current].fileList.current;
- }
- else
- {
- DrawWindow(&sbwin[current], NORMAL);
- DrawError(errorMsg[error]);
- DrawWindow(&sbwin[current], HIGHLIGHT);
- }
- }
- else
- {
- DrawWindow(&sbwin[current], NORMAL);
- DrawError(errorMsg[error]);
- DrawWindow(&sbwin[current], HIGHLIGHT);
- }
- break;
- case PAUSED:
- sbwin[current].fileList.current->status = PLAYING;
- ResumeSnd(FindFileType(sbwin[current].fileList.current->filename));
- break;
- case PLAYING:
- sbwin[current].fileList.current->status = STOPPED;
- sbwin[current].fileList.active = NULL;
- StopSnd(FindFileType(sbwin[current].fileList.current->filename));
- break;
- }
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case SPACE:
- if(sbwin[current].fileList.active != NULL)
- if(sbwin[current].fileList.active->status == PLAYING)
- {
- sbwin[current].fileList.active->status = PAUSED;
- PauseSnd(FindFileType(sbwin[current].fileList.active->filename));
- }
- else
- {
- sbwin[current].fileList.active->status = PLAYING;
- ResumeSnd(FindFileType(sbwin[current].fileList.active->filename));
- }
- DrawFileList(&sbwin[current], HIGHLIGHT);
- break;
-
- case ESC:
- if(sbwin[0].status & SELECTABLE)
- if(sbwin[0].fileList.active != NULL)
- if(sbwin[0].fileList.active->status != STOPPED)
- StopSnd(FindFileType(sbwin[0].fileList.active->filename));
- if(sbwin[1].status & SELECTABLE)
- if(sbwin[1].fileList.active != NULL)
- if(sbwin[1].fileList.active->status != STOPPED)
- StopSnd(FindFileType(sbwin[1].fileList.active->filename));
- break;
- case F1:
- // draw current window unhighlighted
- DrawWindow(&sbwin[current], NORMAL);
- // display driver information window
- if(DrawDrvrInfo(4, 9, Version(), &ctvoice, &ctvdsk, &auxdrv, &sbfmdrv,
- &sbmidi) == ERROR)
- DrawError(memErr);
- // draw current window highlighted
- DrawWindow(&sbwin[current], HIGHLIGHT);
- break;
- default:
- break;
- }
- }
- while(choice != ESC);
- DemoExit(EXIT_SUCCESS);
- }
-
- /*************************************************************************
- * FUNCTION: GETFILES - creates VOC and MID/CMF filename structures.
- *
- * Inputs: midStat - SBMIDI driver availability status (LOADED or MISSING).
- * Inputs: cmfStat - SBFMDRV driver availability status (LOADED or MISSING).
- *
- * Output: none
- *************************************************************************/
- void GetFiles(int midStat, int cmfStat)
- {
- int error;
-
- // get VOC file names in current directory
- if((error = GetFileList(&sbwin[0].fileList.head, "*.voc")) == MEMERR)
- {
- DrawError(dirMemErr);
- DemoExit(EXIT_FAILURE);
- }
- if(error != FILERR)
- // sort VOC filelist and place start, stop, and current pointers
- InitFileList(&sbwin[0].fileList, sbwin[0].size.y - ((mixer == ON)? 3 : 1));
- else
- sbwin[0].status = ~VIEWABLE & ~SELECTABLE;
-
- if((midStat == LOADED) || !(sbwin[1].status & SELECTABLE))
- // get MID file names in current directory
- if((error = GetFileList(&sbwin[1].fileList.head, "*.mid")) == MEMERR)
- {
- DrawError(dirMemErr);
- DemoExit(EXIT_FAILURE);
- }
- else
- if(error == FILERR)
- sbwin[1].status = ~VIEWABLE & ~SELECTABLE;
-
- if((cmfStat == LOADED) || !(sbwin[1].status & SELECTABLE))
- // get CMF file names in current directory
- if((error = GetFileList(&sbwin[1].fileList.head, "*.cmf")) == MEMERR)
- {
- DrawError(dirMemErr);
- DemoExit(EXIT_FAILURE);
- }
-
- if((error != FILERR) || (sbwin[1].status & VIEWABLE))
- {
- // sort MID/CMF filelist and place start, stop, and current pointers
- InitFileList(&sbwin[1].fileList, sbwin[1].size.y - ((mixer == ON)? 3 : 1));
- sbwin[1].status = VIEWABLE | SELECTABLE;
- }
- }
-